Omplus.models.Number = Omplus.base.extend(Omplus.models.SingleElement, {
    init:function () {
    },
    omplusType:"Number",
    validators:["NumberValidator"]
});

Omplus.models.String = Omplus.base.extend(Omplus.models.SingleElement, {
    init:function () {
    },
    omplusType:"String"
});

Omplus.models.Email = Omplus.base.extend(Omplus.models.SingleElement, {
    init:function () {
    },
    omplusType:"Email",
    validators:["EmailValidator"]
});

Omplus.models.Boolean = Omplus.base.extend(Omplus.models.SingleElement, {
    init:function () {
        this.value = false;
    },
    omplusType:"Boolean",
    setValue:function (newValue, view) {
        switch (newValue) {
            case true:
            case "True":
            case "true":
                this.value = true;
                break;
            default:
                this.value = false;
        }
        var valid = this.isValid();
        if (!valid) {
            if (view) {
                for (var error in this.errors) {
                    Omplus.globals.getObject(this.omplusName + ".OnErrorModel").notify([this.controller, view, this.errors[error]]);
                }
            }
        }
        if (this.controller)
            Omplus.globals.getObject(this.omplusName + ".OnUpdateModel").notify([this.controller, view, valid]);
    }
});

Omplus.models.DateTime = Omplus.base.extend(Omplus.models.SingleElement, {
    init:function () {
    },
    omplusType:"DateTime",
    date:null,
    year:null,
    month:null,
    day:null,
    time:null,
    hours:null,
    minutes:null,
    seconds:null,
    getYear:function () {
        return this.year;
    },
    getMonth:function () {
        return this.month;
    },
    getDay:function () {
        return this.day;
    },
    getTime:function () {
        return this.time;
    },
    getHours:function () {
        return this.hours;
    },
    getMinutes:function () {
        return this.minutes;
    },
    getSeconds:function () {
        return this.seconds;
    },
    setYear:function (newValue) {
        this.year = newValue;
        this.updateValue();
    },
    setMonth:function (newValue) {
        this.month = newValue;
        this.updateValue();
    },
    setDay:function (newValue) {
        this.day = newValue;
        this.updateValue();
    },
    setTime:function (newValue) {
        this.time = newValue;
        this.updateValue();
    },
    setHours:function (newValue) {
        this.hours = newValue;
        this.updateValue();
    },
    setMinutes:function (newValue) {
        this.minutes = newValue;
        this.updateValue();
    },
    setSeconds:function (newValue) {
        this.seconds = newValue;
        this.updateValue();
    },
    setValue:function (newValue, view) {
        if (newValue != "" && newValue != null && newValue != "None") {
            // sometimes backend returns milliseconds in format 2012-10-05 15:35:15.176137, we don't need milliseconds
            var value = newValue.split(".");
            value = value[0];

            var date = value.split(" ")[0];
            var time = value.split(" ")[1];

                this.year = date.split("-")[0];
                this.month = date.split("-")[1];
                this.day = date.split("-")[2];
            if (time) {
                this.hours = time.split(":")[0];
                this.minutes = time.split(":")[1];
                this.seconds = time.split(":")[2];
            }else{
                this.hours = "00";
                this.minutes = "00";
                this.seconds = "00";
            }
        } else {
            newValue = null;
            if (this.nullable) {
                this.year = null;
                this.month = null;
                this.day = null;
                this.hours = null;
                this.minutes = null;
                this.seconds = null;
            }
        }
        this.value = newValue;
        var valid = this.isValid();
        if (!valid) {
            if (view) {
                for (var error in this.errors) {
                    Omplus.globals.getObject(this.omplusName + ".OnErrorModel").notify([this.controller, view, this.errors[error]]);
                }
            }
        }
        if (this.controller)
            Omplus.globals.getObject(this.omplusName + ".OnUpdateModel").notify([this.controller, view, valid]);
    },
    updateValue:function () {
        this.value = this.year + "-" + this.month + "-" + this.day + " " + this.hours + ":" + this.minutes + ":" + this.seconds;
    }
});